home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / TEGL6B.ARJ / TUTOR.COM / FRAMES.TXT < prev    next >
Text File  |  1991-08-16  |  6KB  |  215 lines

  1. FRAMES
  2. -------------------------------------------------------------------
  3.  
  4. Frames are the core items to the window manager. You create a frame
  5. using a PushImage then save the global variable StackPtr to
  6. manipulate it and to recognise it. StackPtr is of the TYPE
  7. ImageStackPtr. Since this is a pointer it will always be unique to
  8. the frame.
  9.  
  10. Here we create a frame that covers the area (50,50,200,150) on the
  11. screen.
  12.  
  13. BEGINFILE> frame1.pas
  14. {-- frame1.pas}
  15.  
  16. USES teglunit,teglmain;
  17.  
  18. VAR ifs : ImageStkPtr;
  19.  
  20. BEGIN
  21.   easytegl;
  22.   easyout;
  23.   PushImage(50,50,200,150);
  24.   ifs := StackPtr;
  25.   TeglSupervisor;
  26. END.
  27. ENDFILE>
  28.  
  29.  
  30. Notice that we start our program with tegleasy and easyout. It's a
  31. good idea to start your programs this way when you are first
  32. learning how to use the TEGL WINDOWS TOOLKIT because they provide a
  33. simplified startup and a way to exit the program.
  34.  
  35. Specifically tegleasy initializes the graphics system (autodectects
  36. the graphics hardware), the virtual memory manager, the window
  37. manager and it clears the screen too! Easyout places a button in
  38. the lower left corner of the screen that will terminate the program
  39. when it is clicked on. This may seem trivial but in a GUI there has
  40. to be an event to make the program finish, TeglSupervisor never
  41. returns, it just loops waiting for an event.
  42.  
  43. This little program isn't very useful yet because all we have done
  44. is saved the area that this frame covers. If you run it you won't
  45. see anything on the screen to show where the frame is. However, if
  46. you click the right mouse button down and move it around the screen
  47. will will find that there is an invisible frame there that can been
  48. moved. The right mouse button can be used to click on and move any
  49. mobile frame. Lets change it by covering it with something so we
  50. can see it.
  51.  
  52.  
  53. BEGINFILE> frame2.pas
  54. {-- frame2.pas}
  55.  
  56. USES teglunit,teglmain;
  57.  
  58. VAR ifs : ImageStkPtr;
  59.  
  60. BEGIN
  61.   easytegl;
  62.   easyout;
  63.   PushImage(50,50,200,150);
  64.   ShadowBox(50,50,200,150);
  65.   ifs := StackPtr;
  66.   TeglSupervisor;
  67. END.
  68.  
  69. ENDFILE>
  70.  
  71.  
  72. Here we have added a line calling the routine ShadowBox. This just
  73. blanks the frame and places a shadowed edge around it. You could
  74. clear the frame by using the bar command like so:
  75.  
  76.        SetViewPort(0,0,GetMaxx,GetMaxy,Clipoff);
  77.        SetFillStyle(SolidFill,White);
  78.        Bar(50,50,200,150);
  79.        SetColor(Black);
  80.        Rectangle(50,50,200,150);
  81.  
  82. This would blank the frame to white and draw a black line around
  83. it. ShawdowBox isn't much move complicated, but it is ready to use.
  84.  
  85. You're probably wondering why we keep saving the StackPtr. Like we
  86. said earlier, you'll need this to manipulate the frame. So lets use
  87. it.
  88.  
  89. The next example adds a button and an associated event to the
  90. frame.
  91.  
  92.  
  93. BEGINFILE> frame3.pas
  94. {-- frame3.pas}
  95. {$F+}
  96.  
  97. USES teglunit,teglmain;
  98.  
  99. VAR ifs : ImageStkPtr;
  100.  
  101. function cancelevent(frame: ImageStkPtr; mouse: MsClickPtr): Word;
  102.   BEGIN
  103.     dropstackimage(ifs);
  104.   END;
  105.  
  106. BEGIN
  107.   easytegl;
  108.   easyout;
  109.   PushImage(50,50,200,150);
  110.   ShadowBox(50,50,200,150);
  111.   ifs := StackPtr;
  112.   DefineSquareButtonText(ifs,0,0,80,30,5,5,'CANCEL',cancelevent);
  113.   TeglSupervisor;
  114. END.
  115.  
  116.  
  117. ENDFILE>
  118.  
  119.  
  120. After compiling and running this you'll probably agree that those
  121. squarebuttons look OK.
  122.  
  123. Now lets add some action to it. This example will press and release
  124. the button. Try holding the left mouse button down and passing it
  125. over the button repeatedly.
  126.  
  127. BEGINFILE> frame4.pass
  128. {-- frame4.pas}
  129. {$F+}
  130.  
  131. USES teglunit,teglmain;
  132.  
  133. VAR ifs : ImageStkPtr;
  134.  
  135. function cancelevent(frame: ImageStkPtr; mouse: MsClickPtr): Word;
  136.   BEGIN
  137.     {-- this will press the button down and if the mouse button }
  138.     {-- is release WHILE it is over the button it will return }
  139.     {-- TRUE. If the mouse cursor passes out of the button without }
  140.     {-- being released then it will return FALSE and }
  141.     {-- releasesquarebutton will be called automatically. }
  142.     if visualsquarebuttonpress(frame,mouse) then
  143.       begin
  144.         {-- was TRUE, we release the button }
  145.         releasesquarebutton(frame,mouse);
  146.         {-- then dispose of the frame. }
  147.         dropstackimage(ifs);
  148.       end;
  149.   END;
  150.  
  151. BEGIN
  152.   easytegl;
  153.   easyout;
  154.   PushImage(50,50,200,150);
  155.   ShadowBox(50,50,200,150);
  156.   ifs := StackPtr;
  157.   DefineSquareButtonText(ifs,0,0,70,30,5,5,'CANCEL',cancelevent);
  158.   TeglSupervisor;
  159. END.
  160.  
  161.  
  162. ENDFILE>
  163.  
  164. At some point you will likely have more than one frame on the
  165. screen. When the mouse clicks on that frame it would be nice to
  166. have it on top of all the other frames.
  167.  
  168. SetAutoRotate(OnOff: Boolean);
  169.  
  170. This sets the automatic rotation of frames. If set to TRUE then any
  171. frame that is clicked on will come to the top of the stack (be the
  172. topmost, and entirely visible).
  173.  
  174. This example will put 25 frames on the screen. Try running it with
  175. autorotate set to FALSE also. Try moving the frames around (using
  176. the right mouse button).
  177.  
  178. BEGINFILE> frame5.pas
  179. {-- frame5.pas}
  180. {$F+}
  181.  
  182. USES teglunit,teglmain;
  183.  
  184.  
  185. function cancelevent(frame: ImageStkPtr; mouse: MsClickPtr): Word;
  186.   BEGIN
  187.     if visualsquarebuttonpress(frame,mouse) then
  188.       begin
  189.         {-- was TRUE, we release the button }
  190.         releasesquarebutton(frame,mouse);
  191.         {-- then dispose of the frame. }
  192.         dropstackimage(frame);
  193.       end;
  194.   END;
  195.  
  196. VAR ifs : ImageStkPtr;
  197.     i : Integer;
  198.  
  199. BEGIN
  200.   easytegl;
  201.   easyout;
  202.   setautorotate(true);
  203.   for i := 1 to 25 do
  204.     BEGIN
  205.       quickframe(ifs,i*10,i*10,150,100);
  206.       DefineSquareButtonText(ifs,0,0,70,30,5,5,'CANCEL',cancelevent);
  207.     END;
  208.   TeglSupervisor;
  209. END.
  210.  
  211.  
  212. ENDFILE>
  213.  
  214.  
  215.